/*
 * $Id: Db.java 31 2008-07-04 07:56:53Z benpu $
 * 
 * Generic database connector class with some simple error handling.
 */

package org.zls.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Db {

	private Connection conn = null;
	private Statement stmt = null;

	/**
	 * @param db_addr
	 * @param db_type
	 * @param db_user
	 * @param db_pass
	 * @param db_datb
	 * @throws SQLException
	 */
	public Db(String db_addr, String db_type, String db_user, String db_pass,
			String db_datb) throws SQLException {
		conn = DriverManager.getConnection("jdbc:" + db_type + "://" + db_addr + "/" + db_datb, db_user, db_pass);
		stmt = conn.createStatement();
	}

	/**
	 * @param query
	 * @return
	 * @throws SQLException
	 */
	public ResultSet executeQuery(String query) throws SQLException {
		return stmt.executeQuery(query);
	}

	public int executeUpdate(String update) throws SQLException {
		return stmt.executeUpdate(update);
	}

	/**
	 * @return the conn
	 */
	public Connection getConn() {
		return conn;
	}

	/**
	 * @param conn
	 *            the conn to set
	 */
	public void setConn(Connection conn) {
		this.conn = conn;
	}
}
